﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admincp_lophoc : AdminPage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Page_PreRender(object sender, EventArgs e)
    {
        this.FillDataToListView();
    }

    protected void ThemMoiLopHoc(object sender, EventArgs e)
    {
        Response.Redirect("qllophoc.aspx?hanhdong=themmoi");
    }

    private void FillDataToListView()
    {
        var lophoc = (from lh in db.LopHocs
                      select lh)
                     .AsEnumerable()
                     .Select((_lh, index) => new
                     {
                         MaLopHoc = _lh.MaLop,
                         TenLopHoc = _lh.TenLop,
                         TenKhoiLop = _lh.KhoiLop.TenKhoiLop,
                         TenNamHoc = _lh.NamHoc.TenNamHoc,
                         TrangThai = _lh.TrangThai
                     });
        lvLopHoc.DataSource = lophoc;
        lvLopHoc.DataBind();
    }
    protected void lvLopHoc_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {

    }
    protected void lvLopHoc_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case "EDIT":
                Response.Redirect("qllophoc.aspx?hanhdong=capnhat&malophoc=" + e.CommandArgument.ToString());
                break;
            case "DELETE":
                LopHoc lophoc = db.LopHocs.Single(lh => lh.MaLop == e.CommandArgument.ToString());
                db.LopHocs.DeleteOnSubmit(lophoc);
                db.SubmitChanges();
                this.FillDataToListView();
                break;
        }
    }
    protected void lvLopHoc_ItemEditing(object sender, ListViewEditEventArgs e)
    {

    }
}